<%@ page import="list.control.Guest" %>
<%@ page import="list.model.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--用户--%>
<%
    String opt = request.getParameter("opt");
    String id = request.getParameter("id");
    String password = request.getParameter("password");
    if (opt != null) {
        switch (opt) {
            case "login":
                if (User.login(id, password)) {
                    if (Guest.makeAuth(session.getId(), id)) {
                        response.sendRedirect("../main.jsp?tag=0");//进入主页面
                    }
                } else {
                    response.sendRedirect("../index.jsp?opt=login&val=failed");//返回登录页面
                }
                break;
            case "register":
                String email = request.getParameter("email");
                if (User.register(id, email, password)) {
                    if (Guest.makeAuth(session.getId(), id)) {
                        response.sendRedirect("../main.jsp?tag=0");//进入主页面
                    }
                } else {
                    response.sendRedirect("../index.jsp?opt=register&val=failed");//返回注册页面
                }
                break;
            case "logout":
                response.sendRedirect("../index.jsp?opt=logout");//返回注册页面
                break;
            default:

        }
    }
%>